<?php
session_start();

if(!isset($_SESSION["user"])){
 header("Location:./admin.html");
}
?>



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员文章管理</title>

    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f4f4;
            color: #333;
            margin: 0;
            padding: 20px;
        }
        .admin-containe {
            max-width: 1000px;
            margin: auto;
            background: #fff;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            opacity: 0.85;
        }
        h1 {
            text-align: center;
        }
        .nav-links {
            padding: 0;
            list-style: none;
            text-align: center;
        }
        .nav-links li {
            display: inline;
            margin-right: 20px;
        }
        .nav-links a {
            text-decoration: none;
            color: #007bff;
            font-weight: bold;
        }
        .nav-links a:hover {
            text-decoration: underline;
        }
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f4f4;
            color: #333;
            margin: 0;
            padding: 20px;
        }
        .admin-c {
            max-width: 800px;
            margin: auto;
            background: #fff;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            opacity: 0.9;
        }
        .admin-container {
            max-width: 1000px;
            margin: auto;
            background: #fff;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            opacity: 0.85;
        }
        .article-header, .actions {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 10px;
        }
        .article-title {
            font-size: 24px;
            margin: 0;
        }
        .article-meta {
            font-size: 14px;
            color: #666;
            opacity: 0.85;
        }
        .article-content {
            line-height: 1.6;
            margin-bottom: 20px;
        }
        .action-button {
            padding: 10px 15px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 5px;
            transition: background-color 0.3s ease;
        }
        .action-button:hover {
            background-color: #0056b3;
        }
        .delete-button {
            background-color: #dc3545;
        }
        .delete-button:hover {
            background-color: #c82333;
        }
        <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
        }
        .search-container {
            max-width: 1000px;
            margin: auto;
            background: #fff;
            padding: 20px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            opacity: 0.85;
        }
        .search-box {
            margin-bottom: 10px;
        }
        .search-box input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-top: 5px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        .search-box button {
            padding: 10px 20px;
            margin-top: 10px;
            background-color: #007bff;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        .search-box button:hover {
            background-color: #0056b3;
        }
        body {
            background-image: url('/dom/img/pexels-photo-1103970.webp'); /* 设置页面背景图片 */
            background-size: cover; /* 背景图片覆盖整个元素 */
            background-repeat: no-repeat; /* 背景图片不重复 */
            background-position: center center; /* 背景图片居中显示 */
            background-attachment: fixed; /* 背景图片固定，不随滚动条滚动 */
        }
    </style>
    </style>
</head>
<body>
    <div class="admin-containe">
    <h1>管理控制台</h1>
        <ul class="nav-links">
            <li><a href="/dom/html/index.php">首页</a></li>
            <li><a href="/dom/admin_html/admin2.php">文章管理</a></li>
            <li><a href="/dom/html/hostadmin2.php">管理员管理</a></li>
            <li><a href="/dom/html/hostadmin.php">用户管理</a></li>
            <li><a href="/dom/admin_html/adminxg.php">修改密码</a></li>
            <li><a href="/dom/html/shangc.php">文件上传</a></li>
        </ul>
    </div>
    <div class="search-container">
        <form class="search-box">
            <input type="text" id="searchInput" name="searchInput" placeholder="输入搜索内容">
            <button type="submit">搜索</button>
        </form>
        <button class="action-button" onclick="window.location.href='/dom/admin_html/add.php'";>添加文章</button>
    </div>

    <div class="admin-container">

        <!-- 文章列表 -->
        <div class="article">
            <div class="article-header">
            </div>
            <div class="article-meta">
                <?php
                include "/opt/lampp/htdocs/dom/html/db.php";
                $searchInput = @$_GET['searchInput'];
                $sql = "select news.id,news.title,news.content,news.buildtime,admin.name from news,admin where news.aid = admin.id";
                if ($searchInput){
                    $sql .= " and news.content LIKE '%$searchInput%'";
                }


                $db = new DB();
                $result = $db->select($sql);
                if(!$result){
                    echo"
                    <h3>暂无数据</h3>
                    ";
                }else{
                    foreach($result as $row){
                        echo"
                        <h2>".$row['title']."</h2>
                        <span>作者: ".$row['name']."</span>
                        <span> | </span>
                        <span>发布时间: ".$row['buildtime']."</span>
                        <span> | </span>
                        <span>ID: ".$row['id']."</span>
                        <h4>".$row['content']."</h4>
                        <button>删除</button>
                        <button>修改</button>
                        
                        ";
                    }
                }
                          
                          
                          
                ?>
            </div>
        </div>
        <!-- 更多文章 -->

    </div>

</body>
</html>